package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import dao.utils.GenericHibernateDAO;
import domain.Clientes;
import domain.Empleados;


public class ClientesDAOImpl extends GenericHibernateDAO implements ClientesDAO {

	public ClientesDAOImpl(Session s) {
		super(s);
	}
	
	
	public boolean guardarCliente(String dni, Session sesion, Clientes cliente){
		Clientes Dni = (Clientes) getSession().createQuery("from Clientes as clie where clie.dni = ?").setString(0, dni).uniqueResult();
		if(Dni !=  null){
			return false;
		}else{
			getSession().save(cliente);
			return true;
		}
	}
	
	@Override
	public boolean borrarCliente(String dni, Session sesion, Clientes clie) {
		
		try {
			Query Dni = sesion.createQuery("select count(clie.dni) from Clientes as clie where clie.dni = ?").setString(0,  dni);
			Long numDni = (Long) Dni.uniqueResult();
			if(numDni == 0){
				return false;
			}else{
				sesion.delete(clie);
				return true;
			}
			
		} catch (Exception e) {
			return false;
		}
		
		
	}


	@SuppressWarnings("unchecked")
	public List<Clientes> findAll() {
		Query q=getSession().createQuery("From Clientes");
		return q.list();
	}


	@Override
	public void insertarCliente(Session sesion, String dni) {
		// TODO Auto-generated method stub
		
	}

}